#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  tweet_rate.py
#       Author @  Huoty
#  Create date @  2016-07-12 16:01:51
#  Description @  
# *************************************************************

from __future__ import print_function

import time
import json
import datetime
try:
    from urllib import urlencode
except ImportError:
    from urllib.parse import urlencode

import requests
from tornado import httpserver, ioloop, web, httpclient


class Application(object):
    def __init__(self):
        self.app = web.Application(handler=self.init_handlers())

    def init_handlers(self):
        return [
            (r"/", IndexHandler),
        ]

    def start(self, port, host):
        http_server = httpserver.HTTPServer(self.app)
        http_server.listen(port, host)
        print("* Running on http://%s:%d" % (host, port))
        ioloop.IOLoop.instance().start()

class IndexHandler(web.RequestHandler):
    def get(self):
        query = self.get_argument('q')
        client = httpclient.HTTPClient()
        response = clinet.fetch("http://search.twitter.com/search.json?" + \
                urlencode({"q": query, "result_type": "recent", "rpp": 100}))
        body = json.loads(response.body)
        now = datetime.datetime.utcnow()
        raw_ol



# Script starts from here

if __name__ == "__main__":
    pass
